package com.wisemoresystem.seal.action.seal.news;

import java.util.List;
import java.util.Map;

import org.ne.framework.data.util.ChkTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.base.tip.Tip;
import com.wisemoresystem.seal.model.t_bank;
import com.wisemoresystem.seal.model.t_seal_new;
import com.wisemoresystem.seal.model.t_seal_type;
import com.wisemoresystem.seal.model.t_seal_type_config;
import com.wisemoresystem.seal.model.t_seal_workflow;
import com.wisemoresystem.seal.service.SealNewService;
import com.wisemoresystem.seal.service.SealTypeConfigService;

/**
 * 新章审核
 * 
 * @author 冯晓东
 *
 */
@Controller("sealNewVerify")
@Scope("prototype")
@RequestMapping("/ix/seal/news/verify")
public class SealNewsApplyVerifyAction extends ProjBaseAction {

	@Autowired
	private SealNewService sealNewService;
	@Autowired
	private SealTypeConfigService sealTypeService;

	/**
	 * 新章审核列表
	 * 
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView list() {

		List<Map<String, Object>> applyingList = sealNewService
				.selectApplyingSealNewList(page);

		ModelAndView mv = new ModelAndView("/jsp/seal/news/verify/list");
		mv.addObject("applyingList", applyingList);
		return mv;
	}

	/**
	 * 审核的详细信息
	 * 
	 * @param seal_new_id
	 *            新章id
	 * @return
	 */
	@RequestMapping("/verify_form")
	public ModelAndView verify_form(String seal_new_id) {

		t_seal_new seal_new = oc.findObjById(seal_new_id, t_seal_new.class);
		t_seal_workflow wkflow = oc.findObjById(seal_new.getWorkflow_id(),
				t_seal_workflow.class);
		List<Map<String, Object>> moduleList = sealNewService
				.selectModuleList(wkflow.get_id());

		t_bank bank = oc.findObjById(seal_new.getBank_id(), t_bank.class);
		t_seal_type type = oc.findObjById(seal_new.getSeal_type_id(),
				t_seal_type.class);
		t_seal_type_config typeConfig = oc.findObjById(
				seal_new.getSeal_type_config_id(), t_seal_type_config.class);

		ModelAndView mv = new ModelAndView("/jsp/seal/news/verify/verify_form");
		mv.addObject("seal_new", seal_new);
		mv.addObject("bank", bank);
		mv.addObject("wkflow", wkflow);
		mv.addObject("moduleList", moduleList);
		mv.addObject("type", type);
		mv.addObject("typeConfig", typeConfig);
		return mv;
	}

	/**
	 * 新章审核
	 * 
	 * @param seal_new_id
	 *            新章id
	 * @param verify_flag
	 *            状态
	 * @param note
	 *            备注
	 * @return
	 */
	@RequestMapping("/verify")
	public ModelAndView verify(String seal_new_id, String verify_flag,
			String note) {

		sealNewService.verify(seal_new_id, verify_flag, note);
		logT.logH("新章审核登记", t_seal_new.class, seal_new_id);
		super.setTipMsg("审批完成!", Tip.Type.success);
		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}

	@RequestMapping("/batch_verify")
	public ModelAndView batch_verify(String ids, String verify_flag, String note) {

		String[] seal_new_id = ids.split(",");
		for (String id : seal_new_id) {
			if (ChkTools.isNotNull(id)) {
				sealNewService.verify(id, verify_flag, note);
				logT.logH("新章审核登记", t_seal_new.class, id);
			}
		}

		super.setTipMsg("审批完成!", Tip.Type.success);
		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}

}